package com.visikard.item;

import org.json.JSONObject;

import com.visikard.widget.expandedlistview.BaseExpandableListItem;

import android.os.Parcel;
import android.os.Parcelable;

public class ItemTransactionRewardPunchKard extends BaseExpandableListItem implements Parcelable {
	
	public static final int DEFAULT_COLLAPSED_HEIGHT = 161;

	long dateTime;
	int isGiftSpecial;
	int campaignType; //new
	String campaignDetailLabel; //new
	int categoryCard; //new
	long purchaseTransactionId;
	long couponId; //new
	int requiredBuy;
	long redeemedTransactionId;
	String redemptionValue;
	String remainingValue;
	String dateTimeWithTimezone;
	int iscoupon;
	String imageGiftKard;
	String originalAmount;
	String redeemCode; //new
	int redeemTime;
	long userId;	
	String kardName;
	String kardImage;	
    long merchantId;
    String address;
    String username;    
    
//    String paymentMethod;
//    String redeemptionCode;   
//    int redeemedCount;
//    String kardNumber;
//    String status;
    
    
    
    public ItemTransactionRewardPunchKard() {
    	super(DEFAULT_COLLAPSED_HEIGHT);
    }
    
    public ItemTransactionRewardPunchKard( JSONObject job ) {
    	super(DEFAULT_COLLAPSED_HEIGHT);
    	
    	if(job == null)
    		return;
    		
    	kardName = job.optString("kardName", "");
        if(kardName == null || kardName.equals("null"))
        	kardName = "";
        
    	userId = job.optLong("userId", -1);
    	
        merchantId = job.optLong("merchantId", -1);
        
        dateTime = job.optLong("dateTime", 0);
        
        isGiftSpecial = job.optInt("isGiftSpecial", 0);
        
        setCampaignType(job.optInt("campaignType", 0));
        setCategoryCard(job.optInt("categoryCard", 0));
        
        
        purchaseTransactionId = job.optLong("purchaseTransactionId", -1);
        setCouponId(job.optLong("couponId", -1));
        
        
        redemptionValue = job.optString("redemptionValue", "0.00");
        if(redemptionValue == null || redemptionValue.equals("null"))
        	redemptionValue = "0.00";
        
        
        setCampaignDetailLabel(job.optString("campaignDetailLabel", ""));
        
        kardImage = job.optString("kardImage", "");
        if(kardImage == null || kardImage.equals("null"))
        	kardImage = "";
        
        redeemedTransactionId = job.optLong("redeemedTransactionId", -1);
        
        remainingValue = job.optString("remainingValue", "0.00");
        if(remainingValue == null || remainingValue.equals("null"))
        	remainingValue = "0.00";
        
        dateTimeWithTimezone = job.optString("dateTimeWithTimezone", "");
        if(dateTimeWithTimezone == null || dateTimeWithTimezone.equals("null"))
        	dateTimeWithTimezone = "";
        
        iscoupon = job.optInt("iscoupon", 0);
        
        imageGiftKard = job.optString("imageGiftKard", "");
        if(imageGiftKard == null || imageGiftKard.equals("null"))
        	imageGiftKard = "";
        
        username = job.optString("username", "");
        if(username == null || username.equals("null"))
        	username = "";
        
//        paymentMethod = job.optString("paymentMethod", "");
//        if(paymentMethod == null || paymentMethod.equals("null"))
//        	paymentMethod = "";
//        
//        redeemptionCode = job.optString("redeemptionCode", "");
//        if(redeemptionCode == null || redeemptionCode.equals("null"))
//        	redeemptionCode = "";
        
        originalAmount = job.optString("originalAmount", "0.00");
        if(originalAmount == null || originalAmount.equals("null"))
        	originalAmount = "0.00";
        
        setRedeemCode(job.optString("redeemCode", ""));        
        
        address = job.optString("address", "");
        if(address == null || address.equals("null"))
        	address = "";
        
//        redeemedCount = job.optInt("redeemedCount", 0);
//        
//        kardNumber = job.optString("kardNumber", "");
//        if(kardNumber == null || kardNumber.equals("null"))
//        	kardNumber = "";
//        
//        status = job.optString("status", "");
//        if(status == null || status.equals("null"))
//        	status = "";
        
        //new api returns
        requiredBuy = job.optInt("requireBuy", 0);
        redeemTime = job.optInt("redeemTime", 0);
    }
    
  //constructor used for pacerlable
	protected ItemTransactionRewardPunchKard(Parcel src){
		super(DEFAULT_COLLAPSED_HEIGHT);
		
		kardName = src.readString();
		userId = src.readLong();
		merchantId = src.readLong();
		dateTime = src.readLong();
		isGiftSpecial = src.readInt();
		setCampaignType(src.readInt());
		setCategoryCard(src.readInt());
		purchaseTransactionId = src.readLong();
		setCouponId(src.readLong());
		redemptionValue = src.readString();
		setCampaignDetailLabel(src.readString());
		kardImage = src.readString();
		redeemedTransactionId = src.readLong();
		remainingValue = src.readString();
		dateTimeWithTimezone = src.readString();
		iscoupon = src.readInt();
		imageGiftKard = src.readString();
		username = src.readString();
//		paymentMethod = src.readString();
//		redeemptionCode = src.readString();
		originalAmount = src.readString();
		setRedeemCode(src.readString());
		address = src.readString();
//		redeemedCount = src.readInt();
//	    kardNumber = src.readString();
//	    status = src.readString();
	    requiredBuy = src.readInt();
	    redeemTime = src.readInt();
	}

	@Override
	public void writeToParcel(Parcel target, int arg1) {
	    target.writeString(kardName);
		target.writeLong(userId);
		target.writeLong(merchantId);
		target.writeLong(dateTime);
		target.writeInt(isGiftSpecial);
		target.writeInt(getCampaignType());
		target.writeInt(getCategoryCard());		
		target.writeLong(purchaseTransactionId);
		target.writeLong(getCouponId());		
		target.writeString(redemptionValue);
		target.writeString(getCampaignDetailLabel());		
		target.writeString(kardImage);
		target.writeLong(redeemedTransactionId);
		target.writeString(remainingValue);
		target.writeString(dateTimeWithTimezone);
		target.writeInt(iscoupon);
		target.writeString(imageGiftKard);
		target.writeString(username);
//		target.writeString(paymentMethod);
//		target.writeString(redeemptionCode);
		target.writeString(originalAmount);
		target.writeString(getRedeemCode());		
		target.writeString(address);
//		target.writeInt(redeemedCount);
//		target.writeString(kardNumber);
//		target.writeString(status);
		target.writeInt(redeemTime);
		target.writeInt(requiredBuy);
	}
	
	public static final Parcelable.Creator<ItemTransactionRewardPunchKard> CREATOR = new Creator<ItemTransactionRewardPunchKard>() {
		@Override
		public ItemTransactionRewardPunchKard createFromParcel(Parcel source) {
			return new ItemTransactionRewardPunchKard(source);
		}

		@Override
		public ItemTransactionRewardPunchKard[] newArray(int size) {
			return new ItemTransactionRewardPunchKard[size];
		}
	};

	public String getKardName() {
		return kardName;
	}

	public long getUserId() {
		return userId;
	}

	public long getMerchantId() {
		return merchantId;
	}

	public long getDateTime() {
		return dateTime;
	}

	public int getIsGiftSpecial() {
		return isGiftSpecial;
	}

	public long getPurchaseTransactionId() {
		return purchaseTransactionId;
	}

	public String getRedemptionValue() {
		return redemptionValue;
	}

	public String getKardImage() {
		return kardImage;
	}

	public long getRedeemedTransactionId() {
		return redeemedTransactionId;
	}

	public String getRemainingValue() {
		return remainingValue;
	}

	public String getDateTimeWithTimezone() {
		return dateTimeWithTimezone;
	}

	public int getIscoupon() {
		return iscoupon;
	}

	public String getImageGiftKard() {
		return imageGiftKard;
	}

	public String getUsername() {
		return username;
	}

//	public String getPaymentMethod() {
//		return paymentMethod;
//	}
//
//	public void setPaymentMethod(String paymentMethod) {
//		this.paymentMethod = paymentMethod;
//	}
//
//	public String getRedeemptionCode() {
//		return redeemptionCode;
//	}
//	
//	public void setRedeemptionCode(String redeemptionCode) {
//		this.redeemptionCode = redeemptionCode;
//	}

	public String getOriginalAmount() {
		return originalAmount;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

//	public int getRedeemedCount() {
//		return redeemedCount;
//	}
//
//	public void setRedeemedCount(int redeemedCount) {
//		this.redeemedCount = redeemedCount;
//	}
//
//	public String getKardNumber() {
//		return kardNumber;
//	}
//
//	public void setKardNumber(String kardNumber) {
//		this.kardNumber = kardNumber;
//	}
//
//	public String getStatus() {
//		return status;
//	}
//
//	public void setStatus(String status) {
//		this.status = status;
//	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getRequiredBuy() {
		return requiredBuy;
	}

	public void setRequiredBuy(int requiredBuy) {
		this.requiredBuy = requiredBuy;
	}

	public int getRedeemTime() {
		return redeemTime;
	}

	public void setRedeemTime(int redeemTime) {
		this.redeemTime = redeemTime;
	}

	public int getCampaignType() {
		return campaignType;
	}

	public void setCampaignType(int campaignType) {
		this.campaignType = campaignType;
	}

	public String getCampaignDetailLabel() {
		return campaignDetailLabel;
	}

	public void setCampaignDetailLabel(String campaignDetailLabel) {
		this.campaignDetailLabel = campaignDetailLabel;
	}

	public int getCategoryCard() {
		return categoryCard;
	}

	public void setCategoryCard(int categoryCard) {
		this.categoryCard = categoryCard;
	}

	public long getCouponId() {
		return couponId;
	}

	public void setCouponId(long couponId) {
		this.couponId = couponId;
	}

	public String getRedeemCode() {
		return redeemCode;
	}

	public void setRedeemCode(String redeemCode) {
		this.redeemCode = redeemCode;
	}
}
